package com.zjj.distributed.zk.curator.caches;

import com.zjj.distributed.zk.curator.CuratorBaseOperations;
import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.recipes.cache.TreeCache;
import org.apache.curator.framework.recipes.cache.TreeCacheEvent;
import org.apache.curator.framework.recipes.cache.TreeCacheListener;
import org.junit.Test;

/**
 * @author zhanglei.zjj
 * @description TODO
 * @date 2023/6/20 21:34
 */
@Slf4j
public class TreeCacheTest extends CuratorBaseOperations {
    public static final String TREE_CACHE = "/tree-path";

    @Test
    public void testTreeCache() throws Exception {
        createIfNeed(TREE_CACHE, "treePath");
        TreeCache treeCache = new TreeCache(curatorFramework, TREE_CACHE);
        treeCache.getListenable().addListener(new TreeCacheListener() {
            @Override
            public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception {
                log.info(" tree cache: {}", event);
            }
        });
        treeCache.start();
    }
}
